<?php
/***
 * 描述：PC前台首页面
 * @category		Www		
 * @package			Action			
 * @subpackage		
 * @author			wanght <whtaok@gmail.com>
 * @since			2013-4-6
 * @version			$Id: IndexAction.class.php 84 2013-12-03 16:38:08Z whtaok@gmail.com $
 */
class IndexAction extends WwwAction {
	
	/**
	 * 描述：初始化模块,不继承Www的初始化方法
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-14
	 */
	protected  function _initialize() {
		
	}
	/**
	 * 描述：PC前台首页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function indexAct() {
		//检查是否已经选择了区域
		$flag = $this->checkShop();
		
		
		//热门商品
		$this->_showHotProdList('A1',10);	//食品粮油
		$this->_showHotProdList('B1');	//酒水饮料
		$this->_showHotProdList('C1');	//日用百货
		//$this->_showHotProdList('D1',4);	//套餐盒饭
		$this->_showHotProdList('A107');	//套餐盒饭
		$this->_showHotProdList('A203',4);	//套餐盒饭
		//$this->_showAllD1ProdList();		//显示所有套餐盒饭
		$this->_showTgProdList();
		//$this->assign('lunxun',m_get_ads('index_top_lunxun'));
		$this->assign('ads',m_get_ads());
		$this->display('index');
	}
	
	/**
	 * 描述：显示配送区域列表
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function showChgshopAct(){
		$mod = new ShopLibModel();
		$shopList = $mod->field('id,name,address,district,deliver_around,link_way')->findOpenedList();
		$this->assign('shopList',$shopList);
		exit($this->fetch('shop'));
		//$this->display('shop');
	}
	
	/**
	 * 描述：切换配送区域
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function doChgshopAct(){
		$mod = new ShopLibModel();
		$list = $mod->field('id,address,district')->findOpenedList(I('shop_id'));
		if(count($list)==1){
			$rtnData = array(
					'error'=>0,
					'message'=>'选择成功',
			);
			cookie(COK_SHOP,$list[0]['id'].'|'.$list[0]['district'].'|'.$list[0]['address']);
			session(SES_SHOP_ID,$list[0]['id']);
		}else{
			$rtnData = array(
					'error'=>1,
					'message'=>'该区域尚未开始营业，请稍后',
			);
		}
		$this->ajaxReturn($rtnData);
	}
	/**
	 * 描述：关于我们
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function showAboutAct(){
		$flag = $this->checkShop();
		$mod = new ShopSettingModel();
		$list = $mod->findAboutList();
		$detail = $mod->findAboutDetail(I('id'));
		if($detail && I('id')){
			$this->setPageTitle($detail['title']);
			$this->assign('list',$list);
			$this->assign('detail',$detail);
			$this->assign('leftList',$list[$detail['type']]);
			$this->display('about');
		}else{
			$this->error("未找到相关信息！如有问题请联系客服");
		}
	}
	
	
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	/**
	 * 描述：根据分类查询热门商品
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	protected function _showHotProdList($cate_code,$num=0){
		$savePath = C('REALPATH_SHOP').'/'.$this->curr_shop_id.'/'.$cate_code;
		$hotProdList = F_CACHE($savePath);
		if(is_array($hotProdList)){
			if($num>0){
				$hotProd['list'] = array_slice($hotProdList, 0, $num);
			}else{
				$hotProd['list'] = $hotProdList;
			}
			
			$this->assign($cate_code.'Data',$hotProd);
		}
	}
	
	protected function _showAllD1ProdList(){
		$mod = new ProductPriceViewModel();
		$modWhere = array(
				'is_show'=>1, //上架店铺开关
				'base_is_show'=>1, //上架总开关
				'cate_code1'=>'D1',
		);
		$mod->buildPricedFields($this->curr_shop_id);
		$list = $mod->field('prod_id,name,spec,spec_unit,spec_qty,price_real,price_sale,stock_qty')->setModWhere($modWhere)->select();
		$this->assign('D1ListAll',$list);
	}

}

?>